use crypto::mac::Mac;
use serde_json::Value;

#[test]
fn test1() {
    let dir = crate::mylib::util_file::get_folder("/public/attr/2023/abc.txt");
    println!("dir:{}", dir);
    assert_eq!("/public/attr/2023", dir);
}

#[tokio::test]
async fn test2() {
    let url = "https://api.weixin.qq.com/cgi-bin/component/api_component_token";
    println!("url:{}", url);

    let data = serde_json::json!({
      "component_appid": "wxb6e15355d50bd9bf",
      "component_appsecret": "f4d3ec6e9dcf4a60b2d95168e90a3c4c",
      "component_verify_ticket": "ticket@@@vVSwra1riJKFJy-rByLLVrmx58znws0oOdiXyO_JoxSXnB5SF3hQz7KdMX2zuM5jqlqHgpLFbOvJqaL1oKO6vQ"
    });

    let client = reqwest::Client::new();
    let res = client.post(url).json(&data).send().await.unwrap();

    //println!("res:{}", res.text().await.unwrap());

    let obj = res.json::<serde_json::Value>().await.unwrap();
    println!("obj:{:?}", obj);

    let errcode = obj.get("errcode").and_then(serde_json::Value::as_i64).unwrap_or_default();
    println!("errcode:{:?}", errcode);

    println!("\n\nDone!");

    assert_eq!("1", "1");
}

#[tokio::test]
async fn test3() {
    let baidu = crate::mylib::baidu::Baidu {
        app_id: 7023282,
        api_key: "xxxxxxxxx".to_string(),
        secret_key: "xxxxxxxxxxxxxx".to_string(),
    };

    let rs = baidu.parse_qrcode("http://fleet.tc1680.cn/attr/table/2025-08-26/ZYXh54xM8y.jpg").await;
    println!("rs:{:?}", rs);

    assert_eq!("1", "1");
}

#[tokio::test]
async fn test4() {
    let aliyun = crate::mylib::aliyun::Aliyun {
        access_key_id: "LTAI5tQm1piRGsFxzPsY6uKJ".to_string(),
        access_key_secret: "9b3u9CiZdw5aWQQieTq3uUIzyRs1BA".to_string(),
        algorithm: "ACS3-HMAC-SHA256".to_string(),
    };

    let file_path = "C:\\Users\\Administrator\\Pictures\\微信图片_20251027145632_19_4.jpg";

    let rs = aliyun.read_bank_card_info_by_file(file_path).await;

    println!("rs:{:?}", rs);

    assert_eq!("1", "1");
}

#[test]
fn test5() {
    let s = "2024-04-24至2034-04-24";
    //let s = "2024.04.24-2034.04.24";

    let rs: Vec<_> = s.split(&['至'][..]).map(|v| v.trim()).filter(|v| !v.is_empty()).collect();
    //let rs:Vec<_> = s.split('-').map(|v| v.trim()).filter(|v| !v.is_empty()).collect();

    println!("rs:{:?}", rs);
    assert_eq!("1", "1");
}

#[test]
fn test6() {
    // 测试其他情况
    let test_cases = vec![
        "table_url['LAY-table']='generalquery?funtoken=72EEF63A5ABF01B474AD8A6B97DC8F91280B1D58DE85C54E6C370FC0A537CF237BDF58ED3C3CA3B8546E1900021DDCE5C6D5A2C8DA992288CEA7790D284989B443EE65A679BAB847CD8033D1DF43C20B39D5656D7040062C59AC3F1AF138B5A6&id=' + form_id;",
        "funtoken=yt_currentoperationschedule_mngr&id=2",
        "funtoken=test_value&other=param",
        "funtoken=single_value",
        "id=2&funtoken=yt_currentoperationschedule_mngr",
        "no_funtoken_here",
    ];

    for case in test_cases {
        let re = regex::Regex::new(r#"generalquery\?funtoken=([^&]*)"#).unwrap();

        let s = re.captures(case).and_then(|caps| caps.get(1)).map(|m| m.as_str().to_string());
        println!("\n{:?}", s);
    }
}

 
#[tokio::test]
async fn test7() {
    let esing = crate::mylib::esign::Esign {
        domain: "https://smlopenapi.esign.cn".to_string(),
        appid: "7439090752".to_string(),
        secret: "a0d051c5759ced9fd98ebdafbb1ace61".to_string(),
    }; 

    let file_path = "C://Users//Administrator//Documents//汽车票代售合作协议.pdf";
    let rs = esing.get_file_upload_url(file_path, "汽车票代售合作协议.pdf").await; 
    match rs {
        Ok(bean) => {
            println!("\nbean:{:?}\n", bean);
            let rs = esing.upload_file(file_path, &bean.content_md5, &bean.content_type, &bean.file_id, &bean.file_upload_url).await;
            match rs {
                Ok(v) => {println!("\n上传结果：{}", v);},
                 Err(e) => {println!("\n{:?}", e);},
            }
        },
        Err(e) => {println!("\n{:?}", e);},
    } 

    assert_eq!("1", "1");
} 

 
#[tokio::test]
async fn test8() {
    let esing = crate::mylib::esign::Esign {
        domain: "https://smlopenapi.esign.cn".to_string(),
        appid: "7439090752".to_string(),
        secret: "a0d051c5759ced9fd98ebdafbb1ace61".to_string(),
    }; 

    let rs = esing.get_create_template_url("6b592f673a1e4a76b33607298d47a098", "汽车票代售合作协议20112501").await; 
    match rs {
        Ok(bean) => {
            println!("\nbean:{:?}\n", bean); 
        },
        Err(e) => {println!("\n{:?}", e);},
    } 

    assert_eq!("1", "1");
} 

#[tokio::test]
async fn test9() {
    let esing = crate::mylib::esign::Esign {
        domain: "https://smlopenapi.esign.cn".to_string(),
        appid: "7439090752".to_string(),
        secret: "a0d051c5759ced9fd98ebdafbb1ace61".to_string(),
    }; 

    let rs = esing.get_template_element("6bd1a28df73940188e59dae2bd51c629").await;
    match rs {
        Ok(bean) => {
            println!("\nbean:{:?}\n", bean); 
        },
        Err(e) => {println!("\n{:?}", e);},
    } 

    assert_eq!("1", "1");
} 